{% import "macros.html" as macros %}

{% include "question/question_card.html" %}

{% if answers %}
    <div class="clean"></div>

    {% include "question/answer_tab_bar.html" %}

    <div class="clean"></div>
    <div class="pager">
        {{ macros.paginator(paginator_context, anchor='#sort-top') }}
    </div>
    <div class="clean"></div>

    {% if settings.SHOW_ACCEPTED_ANSWER_FIRST == False %}
        {% if thread.has_accepted_answer() and answers and thread.accepted_answer != answers[0] %}
            <a class="best-answer-link" href="{{ thread.accepted_answer.get_absolute_url() }}">
                {% trans %}See the accepted answer{% endtrans %}
            </a>
        {% endif %}
    {% endif %} 

    {% for answer in answers %}
        {% include "question/answer_card.html" %}
        {% if loop.index == 1 and 'QUESTION_PAGE_ANSWER_BANNER'|show_block_to(request.user) %}
            <div class="banner">{{ settings.QUESTION_PAGE_ANSWER_BANNER|safe }}</div>
        {% endif %}
    {% endfor %}

    <div class="pager">
        {{ macros.paginator(paginator_context, anchor='#sort-top') }}
    </div>
    <div class="clean"></div>
{% elif settings.QUESTION_PAGE_ALWAYS_SHOW_ANSWER_BANNER %}
    <div class="clearfix"></div>
    {% if 'QUESTION_PAGE_ANSWER_BANNER'|show_block_to(request.user) %}
        <div class="banner">{{ settings.QUESTION_PAGE_ANSWER_BANNER|safe }}</div>
    {% endif %}
{% endif %}

<div style="clear:both"></div>
{# buttons and form below cannot be cached #}
{% if not (thread.closed or settings.READ_ONLY_MODE_ENABLED) %}
    {% if new_answer_allowed %}{# show answer input or not #}
        {% if request.user.is_authenticated() or settings.ALLOW_POSTING_BEFORE_LOGGING_IN %}
            {% include "question/new_answer_form.html" %}
        {% else %}
            <a class="button submit"
                href="{{settings.LOGIN_URL}}?next={% url question question.id %}"
                >{{ settings.WORDS_LOGIN_SIGNUP_TO_ANSWER|escape }}</a>
        {% endif %}
    {% else %}
        {# TODO: make this button open in-place answer editor, if answer is on the same page #}
        <a
            class="button submit"
            href="{% url "edit_answer" previous_answer.id %}"
        >{{ settings.WORDS_EDIT_YOUR_PREVIOUS_ANSWER|escape }}</a>
        <span>{{ settings.WORDS_ONLY_ONE_ANSWER_PER_USER_IS_ALLOWED|escape }}</span>
        <div class="invisible">
            {# hidden because we still need js from the tinymce widget #}
            {% include "question/new_answer_form.html" %}
        </div>
    {% endif %}
{% endif %}
